package com.lx.sophon.ui.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.lx.sophon.R
import com.zl.weilu.saber.annotation.BindViewModel
import com.zl.weilu.saber.annotation.OnChange
import com.zl.weilu.saber.api.Saber
import com.zl.weilu.saber.viewmodel.HomeViewModel


class HomeFragment : Fragment() {
    @BindViewModel
    lateinit var homeViewModel: HomeViewModel
    private lateinit var textView: TextView
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val root = inflater.inflate(R.layout.fragment_home, container, false)
        textView = root.findViewById(R.id.text_home)
        Saber.bind(this)
        return root
    }

    @OnChange(model = "homeViewModel")
    fun setData(text: String) {
        textView.text = text

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        homeViewModel.setText("hello world!")
    }
}